/**
 * Flight.java
 * Dec 20, 2009
 */
package com.dlplay.flightinfo.data;

import java.util.Date;

import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.persistence.Transient;

/**
 * @author zhao yu
 * represent the air flight not real time information
 */

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class RealTimeFlightInfo {
	
	@PrimaryKey
	private String key;	
//	@Persistent
//	private AirFlightCode flightNumber;
	@Persistent
	private RTFlightStatus status;
	@Persistent
	private CityCode from;
	@Persistent
	private CityCode to;
	@Persistent
	private String reception;
	@Persistent
	private AirlineCode airCompany;
	@Persistent
	private Date planArrival;
	@Persistent
	private Date planDeparture;
	@Persistent
	private Date actualArrival;
	@Persistent
	private Date actualDeparture;
	@Persistent
	private Float accuracy;
	@Persistent
	private Date latestUpdate;
	
	protected RealTimeFlightInfo() {
		
	}
	/**
	 * @param flightNumber
	 */
	public RealTimeFlightInfo(AirFlightCode number) {
//		this.flightNumber = number;
		setKey(number.toString());
//		this.id = id;
	}	
	
	/**
	 * @param flightNumber
	 */
	public RealTimeFlightInfo(/*String id,*/ AirFlightCode number, RTFlightStatus status, CityCode from, CityCode to,
			String reception, AirlineCode airCompany, Date planArrival, Date planDeparture, 
			Date actualArrival, Date actualDeparture, Float accuracy) {
//		this.id = id;
//		this.flightNumber = number;
		setKey(number.toString());
		this.status = status;
		this.from = from;
		this.to = to;
		this.reception = reception;
		this.airCompany = airCompany;
		this.planArrival = planArrival;
		this.planDeparture = planDeparture;
		this.actualArrival = actualArrival;
		this.actualDeparture = actualDeparture;
		this.accuracy = accuracy;
	}
	
	/**
	 * @return the key
	 */
	public String getKey() {
		return key;
	}
	/**
	 * @return the status
	 */
	public RTFlightStatus getStatus() {
		return status;
	}
	/**
	 * @param key the key to set
	 */
	public void setKey(String key) {
		this.key = key;
	}
	/**
	 * @return the from
	 */
	public CityCode getFrom() {
		return from;
	}	

	/**
	 * @param from the from to set
	 */
	public void setFrom(CityCode from) {
		this.from = from;
	}

	/**
	 * @return the to
	 */
	public CityCode getTo() {
		return to;
	}

	/**
	 * @param to the to to set
	 */
	public void setTo(CityCode to) {
		this.to = to;
	}

	/**
	 * @return the planArrvial
	 */
	public Date getPlanArrival() {
		return planArrival;
	}

	/**
	 * @param planArrvial the planArrvial to set
	 */
	public void setPlanArrival(Date planArrival) {
		this.planArrival = planArrival;
	}

	/**
	 * @return the planDeparture
	 */
	public Date getPlanDeparture() {
		return planDeparture;
	}

	/**
	 * @param planDeparture the planDeparture to set
	 */
	public void setPlanDeparture(Date planDeparture) {
		this.planDeparture = planDeparture;
	}

	/**
	 * @return the actualArrival
	 */
	public Date getActualArrival() {
		return actualArrival;
	}

	/**
	 * @param actualArrival the actualArrival to set
	 */
	public void setActualArrival(Date actualArrival) {
		this.actualArrival = actualArrival;
	}

	/**
	 * @return the actualDeparture
	 */
	public Date getActualDeparture() {
		return actualDeparture;
	}

	/**
	 * @param actualDeparture the actualDeparture to set
	 */
	public void setActualDeparture(Date actualDeparture) {
		this.actualDeparture = actualDeparture;
	}

	/**
	 * @return the accuracy
	 */
	public Float getAccuracy() {
		return accuracy;
	}

	/**
	 * @param accuracy the accuracy to set
	 */
	public void setAccuracy(Float accuracy) {
		this.accuracy = accuracy;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(RTFlightStatus status) {
		this.status = status;
	}
	
	
	/**
	 * @return the id
	 */
	public String getReception() {
		return reception;
	}
	/**
	 * @set the id
	 */
	public void setReception(String reception) {
		this.reception = reception;
	}
	
	/**
	 * @return the airCompany
	 */
	public AirlineCode getAirCompany() {
		return airCompany;
	}
	/**
	 * @set the airCompany
	 */
	public void setAirCompany(AirlineCode airCompany) {
		this.airCompany = airCompany;
	}
	
	public Date getLatestUpdate() {
		return latestUpdate;
	}
	public void setLatestUpdate(Date latestUpdate) {
		this.latestUpdate = latestUpdate;
	}
	
	/**
	 * @param oldFlight
	 * @return if same, return true. otherwise, return false.
	 * Description: compare the other with this.
	 */
	@Transient
	public boolean compare(RealTimeFlightInfo obj) {
		// TODO: id_3 compare the infomation
		if(obj==null)
			return false;
		
		return key==obj.getKey()&& status == obj.getStatus()
		&& from==obj.getFrom() && to==obj.getTo() && planArrival == obj.getPlanArrival()
		&& planDeparture == obj.getPlanDeparture() && actualArrival == obj.getActualArrival()
		&& actualDeparture == obj.getActualDeparture() && accuracy == obj.getAccuracy();
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "RealTimeFlightInfo [accuracy=" + accuracy + ", actualArrival="
				+ actualArrival + ", actualDeparture=" + actualDeparture
				+ ", airCompany=" + airCompany + ", from=" + from + ", key="
				+ key + ", latestUpdate=" + latestUpdate + ", planArrival="
				+ planArrival + ", planDeparture=" + planDeparture
				+ ", reception=" + reception + ", status=" + status + ", to="
				+ to + "]";
	}
		
}